'''
Author: z417
Date: 2020-11-25 16:07:08
LastEditTime: 2020-11-25 16:14:37
LastEditors: z417
Description: In User Settings
FilePath: \webrunner\demo\test\demo.py
'''
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Yuri'
import pytest
from pages import Google
from webrunner.common.tools import DDT, get_driver, get_env

driver = get_driver()


def test_google():
    driver.get(get_env('BASE_URL'))
    driver.sleep(3)
    assert False


def test_search():
    driver.get(get_env('BASE_URL'))
    # driver._send_keys(Google.searchBox, 'page object')
    d = driver.find_element_by_css_selector('input[class="gLFyf gsfi"]')
    d.send_keys('page object')
    driver.sleep(1)
    driver._click(Google.searchButton)
    driver.sleep(3)
    driver.screen_shot('screenshot/pageObject.png')


@pytest.mark.basedOn
@pytest.mark.parametrize("case", DDT('DDT/demo.yml'))
def test_eval(case, record_xml_attribute):
    """write description here"""
    record_xml_attribute('name', case.keyPoints)
    record_xml_attribute('Jira', 'story-397')
    assert eval(case.input) == case.expect


@pytest.mark.basedOn
def test_01():
    driver.hotPlug.myFunc("webRunner")


@pytest.mark.common
def test_02(login):
    login('hello 你好')
    driver.hotPlug['myFunc']("webRunner")


@pytest.mark.common
def test_rerun(func_hook):
    func_hook.execute_script('alert("hello this is func_hook")')
    _b = func_hook.switch_to.alert
    func_hook.sleep(3)
    _b.accept()
    func_hook.sleep(3)
    js = "document.write(\"<h1>This is a rerun</h1>\");"
    func_hook.execute_script(js)
    func_hook.sleep(3)
    assert False
